package com.welsy.usermgt.utils
{
	import mx.collections.ArrayCollection;
	import com.welsy.usermgt.model.UserMgtModelLocator;
	import mx.controls.Alert;
	import com.welsy.user.model.UserModelLocator;
	
	public class UserRoleManager
	{
		
			/**
			 * Returns the available user roles from the server
			 * as a ArrayCOllection of Strings
			 **/
			public static function getAvailableUserRolesTag() : ArrayCollection {
				//Connect to the server and retrieve the data
				return fakeAvailableUserRolesTag();
			}
			
			private static function fakeAvailableUserRolesTag() : ArrayCollection {
				var fake : ArrayCollection = new ArrayCollection;
				fake.addItem("Anonymous");
				fake.addItem("User");
				fake.addItem("Author");
				fake.addItem("Docent");
				fake.addItem("Validator");
				fake.addItem("Administrator");
				fake.addItem("Super User");
				return fake;
			}
			
			public static function getAvailableUserRolesId() : ArrayCollection {
				//Connect to the server and retrieve the data
				return fakeAvailableUserRolesId();
			}
			
			private static function fakeAvailableUserRolesId() : ArrayCollection {
				var fake : ArrayCollection = new ArrayCollection;
				fake.addItem(5); //anonimo
				fake.addItem(10); //utente
				fake.addItem(20); //autore che vede solo i propri corsi, iter...
				fake.addItem(23); //autore
				fake.addItem(25); //validatore
				fake.addItem(28); //amministratore
				fake.addItem(30); //su
				return fake;
			}
			
			//TODO: ok, we have anid from the server.
			//The server should also provide us the list of the names.
			//We have to bond the server ID and the ComboBoxID
			public static function getUserRoleTagIndex(tag : String) : int {
				var it : int = 0;
				for each(var x : String in UserMgtModelLocator.getInstance().userRolesTag) {
					if(x == tag) {
						return it;
					}
					it++;
				}
				return 0; //very stupid not-found behaviour
			}
			
			public static function getUserRoleIdIndex(id : int) : int {
				var it : int = 0;
				for each(var x : int in UserMgtModelLocator.getInstance().userRolesId) {
					if(x == id) {
						return it;
					}
					it++;
				}
				return 0; //very stupid not-found behaviour
			}
	}
}